import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { TypeOrmModuleOptions } from '@nestjs/typeorm';

@Injectable()
export class DatabaseConfig {
  constructor(private configService: ConfigService) {}

  getTypeOrmConfig(): TypeOrmModuleOptions {
    return {
      type: this.configService.get<any>('database.type'),
      host: this.configService.get<string>('database.host'),
      port: this.configService.get<number>('database.port'),
      username: this.configService.get<string>('database.username'),
      password: this.configService.get<string>('database.password'),
      database: this.configService.get<string>('database.database'),
      entities: this.configService.get<string[]>('database.entities'),
      synchronize: this.configService.get<boolean>('database.synchronize'),
    };
  }
}
